﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#include "PropertyComponentTypeEdit.h"
#include "QPushButton"
#include "QVBoxLayout"
#include <QBitmap>

#include "EnableCompileWarning_The_LAST_IncludeInCpp.h"
using namespace PropertyWidget;

CComponentTypeEdit::CComponentTypeEdit(QWidget *parent)
    : QWidget(parent)
{
    setObjectName("TypeEditWidget");
    setStyleSheet("border: 1px solid gray;");
    setFixedSize(32, 63);
    setContentsMargins(0,0,0,0);
    

    //新建类型按钮
    {
        m_btnComponentTypeAdd = new QPushButton(this);
        m_btnComponentTypeAdd->setObjectName("TypeAdd");
        m_btnComponentTypeAdd->setStyleSheet("QPushButton{background-color:rgb(255, 255, 255);\
                                             color: black; border: 1px solid gray;\
                                             border-style: outset;}"
                                             "QPushButton:hover{background-color:#A9A9A9; color:black;}"
                                             "QPushButton:pressed{background-color:#7A7A7A; color:black;\
                                             border-style: inset; }");
        m_btnComponentTypeAdd->setFixedSize(32,32);
        QPixmap picAdd(QStringLiteral(":/images/type_add.png"));
        m_btnComponentTypeAdd->setIconSize(QSize(picAdd.width(),picAdd.height()));
        m_btnComponentTypeAdd->setIcon(picAdd);
        m_btnComponentTypeAdd->setEnabled(false);   // 默认是disable
        connect(m_btnComponentTypeAdd, SIGNAL(clicked(bool)), parent, SLOT(OnComponentTypeAddButtonClick()));
    }
    

    //修改类型按钮
    {
        m_btnComponentTypeModify = new QPushButton(this);
        m_btnComponentTypeModify->setObjectName("TypeModify");
        m_btnComponentTypeModify->setStyleSheet("QPushButton{background-color:rgb(255, 255, 255);\
                                                color: black; border: 1px solid gray;\
                                                border-style: outset;}"
                                                "QPushButton:hover{background-color:#A9A9A9; color:black;}"
                                                "QPushButton:pressed{background-color:#7A7A7A; color:black;\
                                                border-style: inset; }");
        m_btnComponentTypeModify->setFixedSize(32,32);
        QPixmap picModify(QStringLiteral(":/images/type_modify.png"));
        m_btnComponentTypeModify->setIconSize(QSize(picModify.width(),picModify.height()));  
        m_btnComponentTypeModify->setIcon(picModify);
        m_btnComponentTypeModify->setEnabled(false);   // 默认是disable
        connect(m_btnComponentTypeModify, SIGNAL(clicked(bool)), parent, SLOT(OnComponentTypeModifyButtonClick()));
    }

    //布局器
    QVBoxLayout *pVBoxLayout = new QVBoxLayout(this);
    pVBoxLayout->setContentsMargins(0,0,0,0);
    pVBoxLayout->setMargin(0);
    pVBoxLayout->setSpacing(0);
    pVBoxLayout->addWidget(m_btnComponentTypeAdd);
    pVBoxLayout->addWidget(m_btnComponentTypeModify);
}


CComponentTypeEdit::~CComponentTypeEdit(void)
{
}

void CComponentTypeEdit::setComponentTypeAddButtonIcon( QString const &iconFileName )
{
    QIcon andico(iconFileName);
    m_btnComponentTypeAdd->setIcon(andico);
}

void CComponentTypeEdit::setComponentTypeModifyButtonIcon( QString const &iconFileName )
{
    QIcon modifyico(iconFileName);
    m_btnComponentTypeModify->setIcon(modifyico);
}

void CComponentTypeEdit::setEnableComponentTypeAddButton(bool isEnable)
{
    m_btnComponentTypeAdd->setEnabled(isEnable);
}

void CComponentTypeEdit::setEnableComponentTypeModifyButton(bool isEnable)
{
    m_btnComponentTypeModify->setEnabled(isEnable);
}